﻿
using System.Windows;
using System.Windows.Controls;


namespace Company.Shell.Controls
{
    /// <summary>
    /// Valve.xaml 的交互逻辑
    /// </summary>
    public partial class Valve : UserControl
    {
        public Valve()
        {
            InitializeComponent();
        }

        public bool IsOpen
        {
            get { return (bool)GetValue(IsOpenProperty); }
            set { SetValue(IsOpenProperty, value); }
        }
        //定义了一个名为 IsOpen 的依赖属性，用于控制阀门控件的开启/关闭状态
        public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register
            ("IsOpen", typeof(bool), typeof(Valve), new PropertyMetadata(false, new PropertyChangedCallback(isOpenChangedCallback)));

        private static void isOpenChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = (Valve)d;
            if (control == null)
            {
                return;
            }
            if (e.NewValue is bool isopen)
            {
                if(isopen)
                {
                    control._open.Visibility = Visibility.Visible;
                    control._close.Visibility = Visibility.Collapsed;
                }
                else
                {
                    control._open.Visibility = Visibility.Collapsed;
                    control._close.Visibility = Visibility.Visible;
                }

            }
        }
    }
}
